{include file="common/head"/}
<link rel="stylesheet" href="__STATIC__/plugins/spectrum/spectrum.css">
<script>
    var ADMIN = '__ADMIN__';
    var UPURL = "{:url('UpFiles/upImages')}";
    var PUBLIC = "__PUBLIC__";
    var imgClassName, fileClassName;
</script>

<script src="__STATIC__/common/js/jquery.2.1.1.min.js"></script>
<script>
    var edittext = new Array();
</script>
<script src="__STATIC__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__STATIC__/ueditor/ueditor.all.min.js" type="text/javascript"></script>

<div class="admin-main fadeInUp animated">
<fieldset class="layui-elem-field layui-field-title">
    <legend>{$title}</legend>
</fieldset>
<form class="layui-form layui-form-pane">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">基本选项</li>


        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <div class="layui-form-item">
                    <label class="layui-form-label">类型名称</label>
                    <div class="layui-input-4">
                        <input type="text" name="type_name" value="{$info.type_name}" lay-verify="required" placeholder="" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux red">*</div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_delete" lay-filter="is_delete" checked value="0" {if condition="$info['is_delete'] eq 0"}checked{/if}  title="显示">
                        <input type="radio" name="is_delete" lay-filter="is_delete" value="1" {if condition="$info['is_delete'] eq 1"}checked{/if} title="隐藏">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="hidden" name="type_id" value="{$info.type_id}"/>
                    <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{:lang('submit')}</button>
                    <a href="{:url('index')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
                </div>
            </div>

        </div>
    </div>
</form>

</div>
{include file="common/foot"/}
<script>
(function ($) {

})(jQuery);
(function ($) {
    $.fn.extend({
        insertAtCaret: function (myValue, content) {
            alert(myValue);
            var $t = $(this)[0];
            if (document.selection) {
                this.focus();
                sel = document.selection.createRange();
                sel.text = myValue;
                this.focus();
            } else {

                if ($t.selectionStart || $t.selectionStart == '0') {
                    var startPos = $t.selectionStart;
                    var endPos = $t.selectionEnd;
                    var scrollTop = $t.scrollTop;
                    $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
                    this.focus();
                    $t.selectionStart = startPos + myValue.length;
                    $t.selectionEnd = startPos + myValue.length;
                    $t.scrollTop = scrollTop;
                } else {
                    content += myValue;
                    this.focus();
                }
            }
        }
    })
})(jQuery);
layui.use(['form', 'upload', 'element', 'layer', 'laydate'], function () {
    var form = layui.form, upload = layui.upload, laydate = layui.laydate, $ = layui.jquery;
    //日期
    laydate.render({
        elem: '#createtime'
        , type: 'datetime'
        , format: 'yyyy-MM-dd HH:mm'
    });
    //多图片上传
    upload.render({
        elem: '#photos'
        ,url: '{:url("UpFiles/upload")}'
        ,multiple: true
        ,done: function(res){
            //上传完毕
            console.log(res.url)
            var k=$('#uploadshow').find('img').length;
            console.log(k);
            $('#uploadshow').append(' <li class="articlephoto"><img style="padding: 10px;" src="<?php echo config('app.upyun.resourcesHost')?>'+ res.url +'" class="layui-upload-img" name="photo_imgs['+k+'][url]" >' +
                '<button type="button" class="layui-btn" lay-submit="" id="shanchu">删除</button>'+
                '<input placeholder="图片url"  class="layui-input" type="hidden" name="photo_imgs['+k+'][url]" value="'+ res.url +'"/>' +
                '<input placeholder="图片标题"  class="layui-input" type="text" name="photo_imgs['+k+'][title]" value=""/></li>'
            )
        }
    });


    //缩略图上传
    upload.render({
        elem: '#thumbBtn'
        , url: '{:url("UpFiles/upload")}'
        , accept: 'images' //普通文件
        , exts: 'jpg|png|gif' //只允许上传压缩文件
        , done: function (res) {
            console.log(res.url)
            $('#thumbPic').attr('src', "<?php echo config('app.upyun.resourcesHost')?>"+res.url);
            $('#thumb').val(res.url);
        }
    });


    form.on('submit(submit)', function (data) {
        loading = layer.load(1, {shade: [0.1, '#fff']});
        var fields = $(data.form).serialize();
        $.ajax({
            url: "",
            data: fields,
            type: 'post',
            dataType: 'json',
            success: function (res) {

                if (res.code > 0) {
                    layer.msg(res.msg, {icon: 1, time: 1000}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            },
            error: function () {

            },
            complete: function () {
                layer.close(loading);
            },
        });
    });

});

$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮

    if($(e.target).closest("#parentname").length == 0 && $(e.target).closest("#add_list li").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#add_list").hide();
    }
})
$("#uploadshow").on('click','button#shanchu',function(){
    $(this).parent('li').remove();
});
</script>